package com.cat.dataStructure;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/count-vowel-strings-in-ranges/description/
 * @create 2025/8/16 08:52
 * @since JDK17
 */

public class Solution21 {
    int judge(String word) {
        char a = word.charAt(0), b = word.charAt(word.length() - 1);
        if (a != 'a' && a != 'e' && a != 'i' && a != 'o' && a != 'u') {
            return 0;
        }
        if (b != 'a' && b != 'e' && b != 'i' && b != 'o' && b != 'u') {
            return 0;
        }
        return 1;
    }

    public int[] vowelStrings(String[] words, int[][] queries) {
        int n = words.length, m = queries.length;
        int[] ans = new int[m], prefix = new int[n + 1];
        for (int i = 0; i < n; i++) {
            prefix[i + 1] = prefix[i] + judge(words[i]);
        }
        for (int i = 0; i < m; i++) {
            ans[i] = prefix[queries[i][1] + 1] - prefix[queries[i][0]];
        }
        return ans;
    }
}
